From c710d479f1b745bd95a73b82fdf6f47be3b9bd36 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 12 Aug 2004 03:07:01 +0000 Subject: [PATCH] Fix #149422, #143457: 2004-08-11 Federico Mena Quintero Fix #149422, #143457: * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_should_respond): Rewrite to take the current focus into account, the contents of the save entry, and the last focus for the shortcuts list. (switch_to_selected_folder): We don't need an assertion on the action here. --- ChangeLog | 11 ++++ ChangeLog.pre-2-10 | 11 ++++ ChangeLog.pre-2-6 | 11 ++++ ChangeLog.pre-2-8 | 11 ++++ gtk/gtkfilechooserdefault.c | 121 +++++++++++++++++++----------------- 5 files changed, 108 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 06d594bfc3..c9ae674ea7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-08-11 Federico Mena Quintero + + Fix #149422, #143457: + + * gtk/gtkfilechooserdefault.c + (gtk_file_chooser_default_should_respond): Rewrite to take the + current focus into account, the contents of the save entry, and + the last focus for the shortcuts list. + (switch_to_selected_folder): We don't need an assertion on the + action here. + Wed Aug 11 20:56:00 2004 Matthias Clasen * gtk/gtkinternals.h: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 06d594bfc3..c9ae674ea7 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2004-08-11 Federico Mena Quintero + + Fix #149422, #143457: + + * gtk/gtkfilechooserdefault.c + (gtk_file_chooser_default_should_respond): Rewrite to take the + current focus into account, the contents of the save entry, and + the last focus for the shortcuts list. + (switch_to_selected_folder): We don't need an assertion on the + action here. + Wed Aug 11 20:56:00 2004 Matthias Clasen * gtk/gtkinternals.h: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 06d594bfc3..c9ae674ea7 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +2004-08-11 Federico Mena Quintero + + Fix #149422, #143457: + + * gtk/gtkfilechooserdefault.c + (gtk_file_chooser_default_should_respond): Rewrite to take the + current focus into account, the contents of the save entry, and + the last focus for the shortcuts list. + (switch_to_selected_folder): We don't need an assertion on the + action here. + Wed Aug 11 20:56:00 2004 Matthias Clasen * gtk/gtkinternals.h: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 06d594bfc3..c9ae674ea7 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2004-08-11 Federico Mena Quintero + + Fix #149422, #143457: + + * gtk/gtkfilechooserdefault.c + (gtk_file_chooser_default_should_respond): Rewrite to take the + current focus into account, the contents of the save entry, and + the last focus for the shortcuts list. + (switch_to_selected_folder): We don't need an assertion on the + action here. + Wed Aug 11 20:56:00 2004 Matthias Clasen * gtk/gtkinternals.h: diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 14649d25f9..5768b12d35 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -4776,9 +4776,6 @@ switch_to_selected_folder (GtkFileChooserDefault *impl) GtkTreeSelection *selection; struct switch_folder_closure closure; - g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN - || impl->action == GTK_FILE_CHOOSER_ACTION_SAVE); - /* We do this with foreach() rather than get_selected() as we may be in * multiple selection mode */ @@ -4800,82 +4797,92 @@ static gboolean gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed) { GtkFileChooserDefault *impl; - int num_selected; + GtkWidget *toplevel; + GtkWidget *current_focus; impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed); - /* First, if the shortcuts list had the focus, we should switch folders rather - * than terminate. - */ - if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view) - { - GtkTreeIter iter; + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + g_assert (GTK_IS_WINDOW (toplevel)); - if (shortcuts_get_selected (impl, &iter)) - shortcuts_activate_iter (impl, &iter); + current_focus = gtk_window_get_focus (GTK_WINDOW (toplevel)); + g_assert (current_focus != NULL); - return FALSE; - } + if (current_focus == impl->browse_files_tree_view) + { + int num_selected; + gboolean all_files, all_folders; - /* Second, check the save entry. If it has a valid name, we are done. */ + file_list: - if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE - || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) - { - GtkFilePath *path; - gboolean is_valid, is_empty; + selection_check (impl, &num_selected, &all_files, &all_folders); - path = check_save_entry (impl, &is_valid, &is_empty); + if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && num_selected != 1) + return TRUE; /* zero means current folder; more than one means use the whole selection */ - if (is_valid) + if (num_selected == 0) { - gtk_file_path_free (path); - return TRUE; + if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE + || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + goto save_entry; /* it makes sense to use the typed name */ + else + return FALSE; } - else if (!is_empty) - return FALSE; - } - /* Third, do we have an empty selection? */ - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN - || impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) + if (num_selected == 1 && all_folders) + { + switch_to_selected_folder (impl); + return FALSE; + } + else + return all_files; + } + else if (current_focus == impl->save_file_name_entry) { - GtkTreeSelection *selection; + GtkFilePath *path; + gboolean is_valid, is_empty; + gboolean is_folder; + gboolean retval; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); - num_selected = gtk_tree_selection_count_selected_rows (selection); - if (num_selected == 0) - return FALSE; - } + save_entry: - /* Fourth, should we return file names or folder names? */ + g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE + || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER); - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN - || impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) - { - gboolean all_files, all_folders; + path = check_save_entry (impl, &is_valid, &is_empty); - selection_check (impl, NULL, &all_files, &all_folders); + if (!is_valid) + return FALSE; - if (num_selected == 1) + is_folder = check_is_folder (impl->file_system, path, NULL); + if (is_folder) { - if (all_folders) - { - switch_to_selected_folder (impl); - return FALSE; - } - else if (all_files) - return TRUE; + change_folder_and_display_error (impl, path); + retval = FALSE; } else - return all_files; + retval = TRUE; + + gtk_file_path_free (path); + return retval; } - else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER - || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) - /* There can be no files selected in folder mode since we don't show them, - * anyway. - */ - return TRUE; + else if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view) + { + /* The focus is on a dialog's action area button, *and* the widget that + * was focused immediately before it is the shortcuts list. Switch to the + * selected shortcut and tell the caller not to respond. + */ + GtkTreeIter iter; + + if (shortcuts_get_selected (impl, &iter)) + shortcuts_activate_iter (impl, &iter); + else + goto file_list; + + return FALSE; + } + else + goto file_list; /* The focus is on a dialog's action area button or something else */ g_assert_not_reached (); return FALSE; -- 2.30.2